<template>

  <elm-page-bb class="elm-edit">
    <div>
      <el-card shadow="hover" style="margin: 0px 0;">
        <div slot="header">
          <span>薪酬信息</span>
        </div>
        <el-form ref="model" :model="model" size="small" label-width="120px">
          <elm-row>
            <el-form-item label="员工姓名">
              <elm-ei v-model="model.emp_code" :disabled="disable"></elm-ei>
            </el-form-item>
            <el-form-item label="工资月份">
              <el-date-picker v-model="model.month" value-format="yyyyMM" type="month" style="width: 100%"
                              :disabled="disable" :rules="[{trigger: 'blur' ,validator: validateNumber}]">
              </el-date-picker>
            </el-form-item>
          </elm-row>
          <elm-row>
            <el-form-item label="工作天数" prop="word_day" :rules="[{trigger: 'blur' ,validator: validateNumber}]">
              <el-input v-model="model.word_day" :disabled="disable">
                <template slot="append">
                  <div style="width: 25px;text-align: center;">天</div>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item label="是否发放" prop="real_salary" :rules="[{trigger: 'blur' ,validator: validateNumber}]">
              <el-select v-model="model.status" :disabled="disable" style="width: 100%">
                <el-option key="0" label="未发放" value="0"></el-option>
                <el-option key="1" label="已发放" value="1"></el-option>
              </el-select>
            </el-form-item>
          </elm-row>
          <elm-row>
            <el-form-item label="应发工资" prop="cope_salary" :rules="[{trigger: 'blur' ,validator: validateNumber}]">
              <el-input v-model="model.cope_salary" :disabled="disable">
                <template slot="append">
                  <div style="width: 25px;text-align: center;">元</div>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item label="实付工资" prop="real_salary" :rules="[{trigger: 'blur' ,validator: validateNumber}]">
              <el-input v-model="model.real_salary" :disabled="disable">
                <template slot="append">
                  <div style="width: 25px;text-align: center;">元</div>
                </template>
              </el-input>
            </el-form-item>
          </elm-row>

          <el-form-item label="备注">
            <el-input type="textarea" v-model="model.remark" :rows="2" :disabled="disable"></el-input>
          </el-form-item>
          <elm-row>
            <el-form-item label="创建时间">
              <el-date-picker v-model="model.create_date" value-format="yyyy-MM-DD" type="date" style="width: 100%"
                              :disabled="disable">
              </el-date-picker>
            </el-form-item>

            <el-form-item label="登记人" prop="create_user">
              <elm-ei v-model="model.create_user" :disabled="disable"></elm-ei>
            </el-form-item>

          </elm-row>

        </el-form>
      </el-card>

    </div>
    <template #bottom>
      <el-button type="success" size="small" @click="submit" model. v-if="!disable">立即保存</el-button>
      <el-button size="small" @click="close" v-if="!disable">取消</el-button>
      <el-button size="small" @click="close" v-if="disable">返回</el-button>
    </template>
  </elm-page-bb>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      model: {
        pid: elm.dialog.request.pid,
        progress:0,
        manager:null,
      },
      disable:false
    }
  },
  async created() {
    if(this.model.create_user==null||this.model.create_user=="")
      this.model.create_user=await this.get_user_ei();
    if (!this.model.create_date) {
      this.model.create_date=dateTostr(new Date())
    }
  },
  mounted() {
    this.DE_INFO = elm.dialog.request;

    this.disable = this.DE_INFO.disable;
  },
  methods: {
    async submit() {
      await this.$refs["model"].validate();
      var res = await elm.post('/business/hrm/salary/UpsertSalary', this.model);
      if (res == true) {
        this.close();
        this.v('保存成功。');
        this.request.callVue.tablebinding();
      }
      else {
        this.error('保存失败，请稍后尝试。');
      }
    },
    async get_user_ei(){
      var res = await elm.post('/system/login/GetUserEi');
      //console.log(res);
      if(res.length>0)
        return res[0].emp_code;
      else
        return "";
    },
  }
}
</script>

<style scoped>
</style>